package com.apes.fn.server.transferVehicle.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 内协交接车明细
 * Creator: linwz
 * CreateDate: 2020-04-27 11:33
 * Description:
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = InnerPickDeliveryUpCarItem.CONST_TABLE_NAME, indexes = {
        @Index(name = "u_car_description", columnList = "inner_pick_delivery_up_car, node_description", unique = true)})
public class InnerPickDeliveryUpCarItem extends Model {
    public static final String CONST_TABLE_NAME = "fn_inner_pick_del_up_car_item";

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "交接车单明细编码", padding = 12)
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "inner_pick_delivery_up_car", referencedColumnName = "id")
    @Comment("交接车单号")
    private InnerPickDeliveryUpCar innerPickDeliveryUpCar;

    @Column(name = "mileage", length = 32)
    @Comment("里程数")
    private String mileage;

    @Comment("油表数")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fuel_meter", nullable = false, referencedColumnName = "id")
    private Enumeration fuelMeter;

    @Column(name = "note", length = 120)
    @Comment("备注")
    private String note;

    @Column(name = "begin_date")
    @Comment("计划送车日期")
    private Date beginDate;

    @Column(name = "other_Side_date")
    @Comment("预计归还日期")
    private Date otherSideDate;

    @States(name = "节点说明", values = {
            @State(id = "create", name = "发起内协"),
            @State(id = "get", name = "内协接车"),
            @State(id = "return", name = "内协归还"),
            @State(id = "confirmReturn", name = "确认收车")
    })
    @Column(name = "node_description", length = 32, nullable = false)
    private String nodeDescription = "create";

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "belong_dept_id", referencedColumnName = "id")
    @Comment("发起门店")
    private Dept belongDept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "other_side_dept_id", referencedColumnName = "id")
    @Comment("接收门店")
    private Dept otherSideDept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dispatcher_dept_id", referencedColumnName = "id")
    @Comment("调度方")
    private Dept dispatcherDept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "chauffeur", referencedColumnName = "id")
    @Comment("司机")
    private PartyRole chauffeur;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dispatcher_uid", referencedColumnName = "id")
    @Comment("调度信息操作人")
    private PartyRole dispatcherUid;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "dispatcher_date")
    @Comment("调度信息操作日期")
    private Date dispatcherDate;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "operate_uid", referencedColumnName = "id")
    @Comment("操作人")
    private PartyRole operateUid;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "operate_date")
    @Comment("操作日期")
    private Date operateDate;

    @Column(name = "commission_Flag", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("提成标记")
    private boolean commissionFlag = true;

}
